package com.prestamomo.vil.ppa.pmvilpage.pmfitter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.prestamomo.vil.ppa.R;
import com.prestamomo.vil.ppa.pmvilapi.PmvilRoute;

import java.util.List;

public class PmvilRouteFiter extends RecyclerView.Adapter<PmvilRouteFiter.PmvilRouteHolde> {
    private Context pmvilRouteCont;
    private List<PmvilRoute.RepayChannelsPmvil> pmvilRouteList;

    public PmvilRouteFiter(Context pmvilRouteCont, List<PmvilRoute.RepayChannelsPmvil> pmvilRouteList) {
        this.pmvilRouteCont = pmvilRouteCont;
        this.pmvilRouteList = pmvilRouteList;
    }

    @NonNull
    @Override
    public PmvilRouteFiter.PmvilRouteHolde onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PmvilRouteHolde(LayoutInflater.from(pmvilRouteCont).inflate(R.layout.source_pmvil_pop_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull PmvilRouteFiter.PmvilRouteHolde holder, int position) {
        holder.routePmvilPopitemTv.setText(pmvilRouteList.get(position).getPmvilkey());
        holder.routePmvilPopitemTv.setOnClickListener(v -> {
            if(routePmvilClick!=null){
                routePmvilClick.setPmvilRoutes(pmvilRouteList.get(position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return pmvilRouteList==null?0:pmvilRouteList.size();
    }

    public class PmvilRouteHolde extends RecyclerView.ViewHolder{
        private TextView routePmvilPopitemTv;
        public PmvilRouteHolde(@NonNull View itemView) {
            super(itemView);
            routePmvilPopitemTv = itemView.findViewById(R.id.source_pmvil_pop_item_tv);
        }
    }

    public interface RoutePmvilClick{
        void setPmvilRoutes(PmvilRoute.RepayChannelsPmvil pmvilRoutes);
    }

    private RoutePmvilClick routePmvilClick;

    public void setRoutePmvilClick(RoutePmvilClick routePmvilClick) {
        this.routePmvilClick = routePmvilClick;
    }
}
